/*
 * @Author: worldzb 
 * @Date: 2019-05-11 15:37:05 
 * @Last Modified by: worldzb
 * @Last Modified time: 2019-05-11 15:39:48
 */


//执行目标页面函数
export function runFunc(func){
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.innerHTML = func+'();'
    document.body.appendChild(script);
}

//执行代码注入
export function runCode(code){
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.innerHTML = code+';';
    document.body.appendChild(script);
}

//自动登录函数
export function login(account){
    if($('.p_info > .link > .name').html()!=undefined){
        console.log('已经登录');
        return 300;
    }
    this.runFunc('LoginModule.popup');
    this.runFunc('LoginModule.viewEvent');
    this.runCode("$('.tab').eq(1).click()");
    
    $('#login_name').focus();
    $('#login_name').val(account[0]);
    
    $('#password_').focus();
    $('#password_').val(account[1]);
    this.runCode("$('.submit-btn').click()");
    var errorStr=$('.error-info.iconfont.icon-warning').eq(1).html();
    if(errorStr=="用户名或密码有误"){
        return 302;
    }else if(errorStr=="该账号已被封禁，如需帮助请联系客服"){
        return 303;
    }else if(errorStr=="操作太频繁请稍后重试"){
        return 304;
    }
}

//自动登录函数2
export function login2(account){
    if($('.p_info > .link > .name').html()!=undefined){
        console.log('已经登录');
        return 300;
    }
    this.runCode("$('.loginLink').click();$('#login_link').click()");
    //runFunc('LoginModule.viewEvent');
    this.runCode("$('.tab').eq(1).click()");
    
    $('#login_name').focus();
    $('#login_name').val(account[0]);
    
    $('#password_').focus();
    $('#password_').val(account[1]);
    this.runCode("$('.submit-btn').click()");
    var errorStr=$('.error-info.iconfont.icon-warning').eq(1).html();
    if(errorStr=="用户名或密码有误"){
        return 302;
    }else if(errorStr=="该账号已被封禁，如需帮助请联系客服"){
        return 303;
    }else if(errorStr=="操作太频繁请稍后重试"){
        return 304;
    }
}

 //自动退出
export function logout(){
    $('.down_list').show();//
    var url=$('.down_list a').eq( $('.down_list a').length-1).attr('href');
    window.location.href=url;
}
export function logout2(callback){
    $('.userlink').mouseover();
    var url=$('#exitLink').attr('href');
    window.location.href=url;
    callback();
}

